<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" 
	xmlns:ui="http://java.sun.com/jsf/facelets" 
	xmlns:p="http://primefaces.org/ui"
	xmlns:oso="http://osoftware.com/facelets" 
	template="/WEB-INF/templates/mainLayout.xhtml">

	<ui:define name="title">
		<h:outputText value="#{resourceBundle['schedule.title']}" />
	</ui:define>

	<ui:define name="pageContent">
		<h:form id="form">

			<p:panel header="#{resourceBundle['panel.search']}" toggleable="true" collapsed="true">
				<p:panelGrid columns="3">
					<oso:selectOneMenu id="speciality" label="#{resourceBundle['schedule.speciality']}"
						value="#{attentionTimeModel.speciality}" converter="specialityConverter"
						items="#{attentionTimeModel.selectableSpecialities}" itemLabel="name">
						<p:ajax event="change" listener="#{attentionTimeController.onSpecialityChange}" update="specialist" />
					</oso:selectOneMenu>

					<oso:selectOneMenu id="specialist" label="#{resourceBundle['schedule.specialist']}"
						value="#{attentionTimeModel.filter.specialist}" converter="specialistConverter"
						items="#{attentionTimeModel.selectableSpecialists}" itemLabel="fullName">
					</oso:selectOneMenu>
				</p:panelGrid>
				<p:commandButton value="#{resourceBundle['btn.search']}" action="search" update="schedule" />
			</p:panel>
			<p:schedule allDaySlot="false" view="agendaWeek" resizable="false" draggable="false"  locale="es" 
				slotMinutes="#{attentionTimeModel.filter.specialist != null?attentionTimeModel.filter.specialist.attentionTimeDuration:30}"
				id="schedule" value="#{attentionTimeController.eventModel}" widgetVar="myschedule" minTime="6">

				<p:ajax event="dateSelect" listener="#{attentionTimeController.onDateSelect}" oncomplete="eventDialog.show()" update="attentionTimeDialog"/>
				<p:ajax event="eventSelect" listener="#{attentionTimeController.onEventSelect}" oncomplete="eventDialog.show()" update="attentionTimeDialog"/>
			</p:schedule>

			<p:dialog widgetVar="eventDialog" header="Detalles del Turno" showEffect="clip" hideEffect="clip" id="attentionTimeDialog">
				<h:panelGrid columns="2">
					<h:outputLabel value="Paciente: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.patient.fullName}" />
					<h:outputLabel value="Fecha: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.date}" />
					<h:outputLabel value="Especialista: " />
					<h:outputText value="#{attentionTimeModel.editedEntity.specialistFee.specialist.fullName}" />
				</h:panelGrid>
				<p:commandButton value="#{resourceBundle['btn.new']}" action="new" />
				<p:commandButton value="#{resourceBundle['btn.edit']}" action="edit" />
				<p:commandButton value="#{resourceBundle['btn.delete']}" action="delete" oncomplete="handleAttentionTimeServerResponse(xhr, status, args)"/>
				<p:commandButton value="#{resourceBundle['confirm']}" action="confirmAttentionTime" oncomplete="handleAttentionTimeServerResponse(xhr, status, args)"/>
			</p:dialog>
			<script type="text/javascript">
		        function handleAttentionTimeServerResponse(xhr, status, args) {
		            if (!args.validationFailed) {
		            	eventDialog.hide();
		            }
		        }
		    </script>
		</h:form>

	</ui:define>


</ui:composition>